const path = require('path')

function resolve(dir) {
  return path.join(__dirname, '', dir)
}

module.exports = {
  transpileDependencies: ['chatarea'],
  chainWebpack: (config) => {
    // 处理 chatarea 的现代语法
    config.module
        .rule('js')
        .test(/\.js$/)
        .include.add(/node_modules[\\/]chatarea/)
        .end()
        .use('babel-loader')
        .loader('babel-loader')
        .options({
          plugins: [
            '@babel/plugin-proposal-optional-chaining',
            '@babel/plugin-proposal-nullish-coalescing-operator'
          ]
        })

    // 处理 JSX
    config.module
        .rule('jsx')
        .test(/\.(jsx|js)$/)
        .exclude.add(/node_modules(?!\/chatarea)/)
        .end()
        .use('babel-loader')
        .loader('babel-loader')
  },
  pages: {
    index: {
      entry: 'examples/main.js',
      template: 'public/index.html',
      filename: 'index.html'
    }
  },
  publicPath: '',
  productionSourceMap: false,
  configureWebpack: {
    resolve: {
      alias: {
        components: resolve('packages/components'),
        mixins: resolve('packages/mixins'),
        styles: resolve('packages/styles'),
        utils: resolve('packages/utils')
      }
    }
  }
}